package gdma.hqdes.webapp.controller;

import gdma.hqdes.bean.HqdProject;
import gdma.hqdes.service.ProjectService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author wangyue
 * @Version 3.0
 * @Date 2024-09-06
 */

@RestController
@RequestMapping("/api/admin/projects")
public class ProjectAdminController {

    @Autowired
    ProjectService projectService;

    @ApiOperation("项目列表")
    @GetMapping("")
    @RequiresPermissions("projects:global")
    public List<HqdProject> listProjects(@ApiParam("单位级别") @RequestParam(value = "scope", required = false) Integer scope,
                                         @ApiParam("关键字") @RequestParam(value = "keyword", required = false) String keyword) {
        return projectService.listProjects(null, null, scope, null, keyword);
    }

    @ApiOperation("保存项目")
    @PostMapping("")
    @RequiresPermissions("projects:global")
    public HqdProject createProject(@RequestBody HqdProject project) {
        project.setId(null);
        return projectService.saveProject(project);
    }

    @ApiOperation("编辑项目")
    @PostMapping("/{id}")
    @RequiresPermissions("projects:global")
    public HqdProject updateProject(@PathVariable("id") Long id,
                                    @RequestBody HqdProject project) {
        project.setId(id);
        return projectService.saveProject(project);
    }

}
